package com.ruoyi.system.ArcusMiddleWare.ArcusInstanceReg;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.system.ArcusMiddleWare.FlaskRecord.FlaskMonitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

@RestController
public class ArcusInstanceReg {
    @Autowired
    private RedisCache redisCache;

    public static final Logger log = LoggerFactory.getLogger(ArcusInstanceReg.class);

    public static ConcurrentHashMap<String, String> instanceRecord;

    @PostMapping("/arcus/instanceReg")
    public int reg(@RequestBody JSONObject jsonObject){
        try{
            log.info(jsonObject.toString());
            String dstInstance = "http://" + jsonObject.get("ip") + ":" + jsonObject.get("port");
            redisCache.setCacheObject((String) jsonObject.get("uuid"), dstInstance, ArcusConstants.HEART_TIME, TimeUnit.SECONDS);
            return 0;
        }catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
}
